﻿using Engine.FileFormats3D.C11Undercover;
using Engine.Graphics.Shaders.C11Undercover;
using Engine.Graphics.Shaders.C11UndercoverShaders;
using SharpDX.Direct3D11;
using System.Collections.Generic;

namespace Engine.Graphics.Shaders
{
    public class C11UndercoverShaderArray
    {
        #region Private Fields

        private Shaders.Wr2Shaders.MaterialColorShader colorShader;
        private Device device;
        private Material000 material000;
        private Material016 material016;
        private Material017 material017;
        private Material032 material032;
        private Material048 material048;
        private Material064 material064;
        private Material080 material080;
        private Material096 material096;
        private Material112 material112;
        private Material128 material128;

        //Material144 material144;
        //Material160 material160;
        private Material176 material176;

        //Material192 material192;
        private Material208 material208;

        private Material224 material224;
        private Material240 material240;
        private Material272 material272;
        private Material288 material288;
        private Material304 material304;
        private Material320 material320;
        private Material336 material336;
        private Material352 material352;
        private Material368 material368;
        private Material384 material384;
        private Material400 material400;
        private Material416 material416;
        private Material432 material432;
        private List<ISetShaderValues> registeredShaders;
        private string shaderpath;
        private StandardEffect standardEffect;

        #endregion Private Fields

        #region Public Constructors

        public C11UndercoverShaderArray(Device device, MaterialManager materialManger, string shaderpath)
        {
            this.shaderpath = shaderpath + "\\C11Undercover\\";
            this.registeredShaders = new List<ISetShaderValues>();
            this.device = device;
            LoadShaders(this.shaderpath, device);
        }

        #endregion Public Constructors

        #region Public Methods

        public List<ISetShaderValues> GetRegisteredShaders()
        {
            return this.registeredShaders;
        }

        public void LoadShaders(string shaderPath, Device device)
        {
            //Load

            this.standardEffect = new StandardEffect(device);
            this.material000 = new Material000(device, shaderPath);
            this.material016 = new Material016(device, shaderPath);
            this.material017 = new Material017(device, shaderPath);
            this.material032 = new Material032(device, shaderPath);
            this.material048 = new Material048(device, shaderPath);
            this.material064 = new Material064(device, shaderPath);
            this.material080 = new Material080(device, shaderPath);
            this.material096 = new Material096(device, shaderPath);
            this.material112 = new Material112(device, shaderPath);
            this.material128 = new Material128(device, shaderPath);
            //this.material144 = new Material144(device, shaderPath, effectPool);
            //this.material160 = new Material160(device, shaderPath, effectPool);
            this.material176 = new Material176(device, shaderPath);
            //this.material192 = new Material192(device, shaderPath, effectPool);
            this.material208 = new Material208(device, shaderPath);
            this.material224 = new Material224(device, shaderPath);
            this.material240 = new Material240(device, shaderPath);
            this.material272 = new Material272(device, shaderPath);
            this.material288 = new Material288(device, shaderPath);
            this.material304 = new Material304(device, shaderPath);
            this.material320 = new Material320(device, shaderPath);
            this.material336 = new Material336(device, shaderPath);
            this.material352 = new Material352(device, shaderPath);
            this.material368 = new Material368(device, shaderPath);
            this.material384 = new Material384(device, shaderPath);
            this.material400 = new Material400(device, shaderPath);
            this.material416 = new Material416(device, shaderPath);
            this.material432 = new Material432(device, shaderPath);
            this.colorShader = new Wr2Shaders.MaterialColorShader(device, "C:\\Dev\\Scenario Editor\\bin\\Debug\\shaders\\");

            this.registeredShaders.Clear();
            this.registeredShaders.Add(this.material000);
            this.registeredShaders.Add(this.standardEffect);
            this.registeredShaders.Add(this.material016);
            this.registeredShaders.Add(this.material017);
            this.registeredShaders.Add(this.material032);
            this.registeredShaders.Add(this.material048);
            this.registeredShaders.Add(this.material064);
            this.registeredShaders.Add(this.material080);
            this.registeredShaders.Add(this.material096);
            this.registeredShaders.Add(this.material112);
            this.registeredShaders.Add(this.material128);
            //this.registeredShaders.Add(this.material144);
            //this.registeredShaders.Add(this.material160);
            this.registeredShaders.Add(this.material176);
            //this.registeredShaders.Add(this.material192);
            this.registeredShaders.Add(this.material208);
            this.registeredShaders.Add(this.material224);
            this.registeredShaders.Add(this.material240);
            this.registeredShaders.Add(this.material272);
            this.registeredShaders.Add(this.material288);
            this.registeredShaders.Add(this.material304);
            this.registeredShaders.Add(this.material320);
            this.registeredShaders.Add(this.material336);
            this.registeredShaders.Add(this.material352);
            this.registeredShaders.Add(this.material368);
            this.registeredShaders.Add(this.material384);
            this.registeredShaders.Add(this.material400);
            this.registeredShaders.Add(this.material416);
            this.registeredShaders.Add(this.material432);
            this.registeredShaders.Add(this.colorShader);
        }

        public ShaderBase SetEffectValues(int materialID, MaterialManager materialManager)
        {
            // material = materialManager.GetMaterial(10);
            Material material = materialManager.GetMaterial(materialID);

            switch ((EnumC11UndercoverMappingMode)material.MappingMode)
            {
                case EnumC11UndercoverMappingMode.Material00:
                case (EnumC11UndercoverMappingMode)1:
                case (EnumC11UndercoverMappingMode)2:
                    material000.SetProperties(materialID, materialManager);
                    return material000.Effect;

                //case EnumC11UndercoverMappingMode.Material16:
                //    material016.SetProperties(material, materialManager);
                //    return material016.Effect;

                //case EnumC11UndercoverMappingMode.Material17:
                //    material017.SetProperties(material, materialManager);
                //    return material017.Effect;

                //case EnumC11UndercoverMappingMode.Material32:
                //case (EnumC11UndercoverMappingMode)33:
                //    material032.SetProperties(material, materialManager);
                //    return material032.Effect;

                //case EnumC11UndercoverMappingMode.Material48:
                //    material048.SetProperties(material, materialManager);
                //    return material048.Effect;

                //case EnumC11UndercoverMappingMode.Material64:
                //    material064.SetProperties(material, materialManager);
                //    return material064.Effect;

                //case EnumC11UndercoverMappingMode.Material80:
                //    material080.SetProperties(material, materialManager);
                //    return material080.Effect;

                //case EnumC11UndercoverMappingMode.Material96:
                //    material096.SetProperties(material, materialManager);
                //    return material096.Effect;

                //case EnumC11UndercoverMappingMode.Material112:
                //    material112.SetProperties(material, materialManager);
                //    return material112.Effect;

                //case EnumC11UndercoverMappingMode.Material128:
                //    material128.SetProperties(material, materialManager);
                //    return material128.Effect;

                ////case EnumC11UndercoverMappingMode.material144:
                ////    material144.SetProperties(material, materialManager);
                ////    return material144.Effect;

                ////case EnumC11UndercoverMappingMode.material160:
                ////    material160.SetProperties(material, materialManager);
                ////    return material160.Effect;

                //case EnumC11UndercoverMappingMode.Material176:
                //    material176.SetProperties(material, materialManager);
                //    return material176.Effect;

                ////case EnumC11UndercoverMappingMode.material192:
                ////    material192.SetProperties(material, materialManager);
                ////    return material192.Effect;

                //case EnumC11UndercoverMappingMode.Material208:
                //    material208.SetProperties(material, materialManager);
                //    return material208.Effect;

                //case EnumC11UndercoverMappingMode.Material224:
                //    material224.SetProperties(material, materialManager);
                //    return material224.Effect;

                //case EnumC11UndercoverMappingMode.Material240:
                //    material240.SetProperties(material, materialManager);
                //    return material240.Effect;

                //case EnumC11UndercoverMappingMode.Material272:
                //    material272.SetProperties(material, materialManager);
                //    return material272.Effect;

                //case EnumC11UndercoverMappingMode.Material288:
                //    material288.SetProperties(material, materialManager);
                //    return material288.Effect;

                //case EnumC11UndercoverMappingMode.Material304:
                //    material304.SetProperties(material, materialManager);
                //    return material304.Effect;

                //case EnumC11UndercoverMappingMode.Material320:
                //    material320.SetProperties(material, materialManager);
                //    return material320.Effect;

                //case EnumC11UndercoverMappingMode.Material336:
                //    material336.SetProperties(material, materialManager);
                //    return material336.Effect;

                //case EnumC11UndercoverMappingMode.Material352:
                //    material352.SetProperties(material, materialManager);
                //    return material352.Effect;

                //case EnumC11UndercoverMappingMode.Material368:
                //    material368.SetProperties(material, materialManager);
                //    return material368.Effect;

                //case EnumC11UndercoverMappingMode.Material384:
                //    material384.SetProperties(material, materialManager);
                //    return material384.Effect;

                //case EnumC11UndercoverMappingMode.Material400:
                //    material400.SetProperties(material, materialManager);
                //    return material400.Effect;

                //case EnumC11UndercoverMappingMode.Material416: // Lights in tunnel. but doesent work correct
                //    material416.SetProperties(material, materialManager);
                //    return material416.Effect;

                //case EnumC11UndercoverMappingMode.Material432: // Lights in tunnel. but doesent work correct
                //    material432.SetProperties(material, materialManager);
                //    return material432.Effect;

                default:
                    // throw new Exception("Set effect value is not implemented");
                    //return this.standardEffect.effect;
                    return this.colorShader.effect;
            }
        }

        #endregion Public Methods

        #region Internal Methods

        internal void Dispose()
        {
            foreach (var item in this.registeredShaders)
            {
                item.Dispose();
            }
            this.registeredShaders.Clear();
        }

        internal void ReloadShaders()
        {
            LoadShaders(this.shaderpath, this.device);
        }

        #endregion Internal Methods
    }
}